<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>基础轮播图</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        .swiper {
            position: relative;
            width: 500px;
            height: 300px;
            margin: 200px auto;
            background-color: red;
            overflow: hidden;
        }

        /* 轮播图片列表 */
        ul {
            position: absolute;
            left: 0;
            top: 0;
            height: 100%;
            list-style: none;
            /* 突破父元素宽度限制 */
            white-space: nowrap;
            font-size: 0;
            transition: left 0.3s;
        }

        /* 用于禁用过渡效果的类名 */
        .no-transition {
            transition: none;
        }

        ul>li {
            display: inline-block;
            width: 500px;
            height: 100%;
            background-color: green;
            font-size: 50px;
            box-shadow: 0 0 5px 0 red inset;
        }



        /* 按钮样式 */
        .swiper-btns {
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 40px;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .swiper-btns>div {
            width: 10px;
            height: 10px;
            background-color: blue;
            border-radius: 50%;
            margin: 0 5px;
            cursor: pointer;
        }
    </style>
</head>

<body>
    <!-- 轮播图盒子 -->
    <div class="swiper">
        <!-- 轮播图列表 -->
        <ul>
            <li>1</li>
            <li>2</li>
            <li>3</li>
        </ul>
        <!-- 轮播图按钮 -->
        <div class="swiper-btns">
            <div value="0"></div>
            <div value="1"></div>
            <div value="2"></div>
        </div>
    </div>
</body>
<script>
    // 获取按钮
    let btn = document.querySelector('.swiper-btns')
    // 获取大盒子
    let box = document.querySelector('.swiper')
    // 获取滚动的盒子
    let ul = document.querySelector('.swiper>ul')

    btn.onclick = function (e) {
        let val = e.target.getAttribute('value')
        if (!val) return
        // 获取最大的盒子的宽度
        let width = box.offsetWidth
        console.log(width);
        ul.style.left = val * -width + 'px'
    }
</script>

</html>